<?php

namespace app\service\admin;

use app\service\base\BaseModel;
use think\facade\Db;

class RolePurviewModel extends BaseModel
{
    protected $name = 'admin_role_purview';

    public function getAll($arrWhere)
    {
        return Db::name($this->name)->where($arrWhere)->select()->toArray();
    }

    public function del($arrWhere)
    {
        if (!empty($arrWhere)) {
            Db::name($this->name)->where($arrWhere)->delete();
        }
    }

    public function addMulti($arrData)
    {
        Db::name($this->name)->insertAll($arrData);
    }

    public function getRowJoinPurview($url, $roleId, $field = '*')
    {
        return Db::name($this->name)
            ->alias('RP')
            ->field($field)
            ->leftJoin('admin_purview AP' , 'RP.admin_purview_id = AP.id')
            ->where('RP.admin_role_id', $roleId)
            ->where('AP.url', $url)
            ->find();
    }

}